# -*- coding: utf-8 -*-
import math
import decimal as dc

def square_number(x):
    root = x ** .5
    return round(root) ** 2 == x

def compute(N):
    m, r = 1.0, None
    dc.getcontext().prec = 50
    pi = dc.Decimal('3.14159265358979323846264338327950288419716939937510')
    
    for n in range(N):
        if square_number(n):
            continue 

        x = pi * dc.Decimal(n).sqrt()
        v = (dc.Decimal(x).exp() + dc.Decimal(-x).exp()) / dc.Decimal(2)
        z = math.cos(math.pi*math.sqrt(n))
            
        t1 = min(math.ceil(v) - v, v - math.floor(v))
        t2 = min(math.ceil(z) - z, z - math.floor(z))
        if t1 < m:
            m, r = t1, -n
            print(m)
        if t2 < m:
            m, r = t2, n
            print(m)
            
    return r

if __name__ == "__main__":
    print(compute(1001))
